import socket
import json

sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
sock.settimeout(1)
sock.bind(("", 8005))
while True:
    try:
        cmdstr = sock.recv(1024)
        print("received cmd string")
        print(cmdstr)
    except:
        print("exception on recv")
    try:
        cmd = json.loads(cmdstr)
        print("parsed cmd string")
        fb = {}
        fb["fl_pos"] = cmd["fl_pos"]
        fb["fl_vel"] = cmd["fl_vel"]
        fb["fl_sft"] = 0
        
        fb["fr_pos"] = cmd["fr_pos"]
        fb["fr_vel"] = cmd["fr_vel"]
        fb["fr_sft"] = 0
        
        fb["bl_pos"] = cmd["bl_pos"]
        fb["bl_vel"] = cmd["bl_vel"]
        fb["bl_sft"] = 0
        
        fb["br_pos"] = cmd["br_pos"]
        fb["br_vel"] = cmd["br_vel"]
        fb["br_sft"] = 0
        print(fb)
        out = json.dumps(fb)
        sock.sendto(out.encode(), ("127.0.0.1", 8001))
        print("loopback feedback")
    except:
        print("exception on parse")
        pass
    


    







